package com.duowei.dw_pos;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.duowei.dw_pos.adapter.OtherPayDetailAdapter;
import com.duowei.dw_pos.bean.DMFKFS;
import com.duowei.dw_pos.bean.JYXMSZ;
import com.duowei.dw_pos.bean.LBZKSZJBXX;
import com.duowei.dw_pos.bean.LBZKSZMXXX;
import com.duowei.dw_pos.bean.Moneys;
import com.duowei.dw_pos.bean.OrderNo;
import com.duowei.dw_pos.bean.PaySet;
import com.duowei.dw_pos.bean.WMLSB;
import com.duowei.dw_pos.bean.WXFWQDZ;
import com.duowei.dw_pos.bean.Wmslbjb_jiezhang;
import com.duowei.dw_pos.bean.YHJBQK;
import com.duowei.dw_pos.bean.Ygsbbc;
import com.duowei.dw_pos.bean.YunFu;
import com.duowei.dw_pos.constant.ExtraParm;
import com.duowei.dw_pos.dialog.CheckOutDialog;
import com.duowei.dw_pos.dialog.ConfirmDialog;
import com.duowei.dw_pos.dialog.KindDiscountFragment;
import com.duowei.dw_pos.event.CheckSuccess;
import com.duowei.dw_pos.event.FinishEvent;
import com.duowei.dw_pos.event.YunSqlFinish;
import com.duowei.dw_pos.event.YunSubmit;
import com.duowei.dw_pos.fragment.OtherPayFragment;
import com.duowei.dw_pos.httputils.DownHTTP;
import com.duowei.dw_pos.httputils.Post6;
import com.duowei.dw_pos.httputils.VolleyResultListener;
import com.duowei.dw_pos.sunmiprint.Prints;
import com.duowei.dw_pos.tools.CartList;
import com.duowei.dw_pos.tools.CloseActivity;
import com.duowei.dw_pos.tools.Net;
import com.duowei.dw_pos.tools.SqlNetHandler;
import com.duowei.dw_pos.tools.Users;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.litepal.crud.DataSupport;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import woyou.aidlservice.jiuiv5.IWoyouService;

public class CheckOutActivity extends AppCompatActivity implements ConfirmDialog.OnconfirmClick,
        KindDiscountFragment.DiscountClick, OtherPayFragment.OnItemClickListener, AdapterView.OnItemClickListener {
    @BindView(R.id.tv_user)
    TextView mTvUser;
    @BindView(R.id.btn_dayin)
    Button mBtnDayin;
    @BindView(R.id.btn_dingdan)
    Button mBtnDingdan;
    @BindView(R.id.tv_time)
    TextView mTvTime;
    @BindView(R.id.tv_zonger)
    TextView mTvZonger;
    @BindView(R.id.tv_zekou)
    TextView mTvZekou;
    @BindView(R.id.tv_yishou)
    TextView mTvYishou;
    @BindView(R.id.tv_daishou)
    TextView mTvDaishou;
    @BindView(R.id.imgzhifubao)
    ImageView mImgzhifubao;
    @BindView(R.id.rl_zhifubao)
    RelativeLayout mRlZhifubao;
    @BindView(R.id.imgweixin)
    ImageView mImgweixin;
    @BindView(R.id.rl_weixin)
    RelativeLayout mRlWeixin;
    @BindView(R.id.tv_table)
    TextView mTvTable;
    @BindView(R.id.tvPersons)
    TextView mTvPersons;
    @BindView(R.id.tv_opener)
    TextView mTvOpener;
    @BindView(R.id.ll_cashier)
    LinearLayout mLlCashier;
    @BindView(R.id.rl_yun)
    RelativeLayout mRlYun;
    @BindView(R.id.imgxianjin)
    ImageView mImgxianjin;
    @BindView(R.id.rl_xianjin)
    RelativeLayout mRlXianjin;
    @BindView(R.id.imgyun)
    ImageView mImgyun;
    @BindView(R.id.progressBar)
    ProgressBar mProgressBar;
    @BindView(R.id.ll_change)
    LinearLayout mLlChange;
    @BindView(R.id.linearLayout)
    LinearLayout mLinearLayout;
    @BindView(R.id.listView)
    ListView mListView;
    private ArrayList<WMLSB> list_wmlsb = new ArrayList<>();
    private Handler mHandler = new Handler();
    private float mTotalMoney = 0;//总额(原始价格总额)
    private float mActualMoney = 0;//实际金额
    private float mYishou = 0.00f;
    private float mYingshou = 0.00f;
    private float mZhaoling = 0.00f;

    private final int YUPAYREQUEST = 100;
    public final static int RESURTCODE = 1000;

    private IWoyouService woyouService;
    private ServiceConnection connService = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            woyouService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            woyouService = IWoyouService.Stub.asInterface(service);
            mBtnDayin.setEnabled(true);
        }
    };
    private Wmslbjb_jiezhang mWmlsbjb;
    private WMLSB[] mWmlsbs;
    private Intent mIntent;
    private String mWmdbh;
    private String mPad;
    private Prints mPrinter;
    private ConfirmDialog mConfirmDialog;
    private String mOrderstytle;
    //云会员付款方式
    private List<YunFu> mYunPayStytle;
    //云会员后的数据
    private ArrayList<WMLSB> mListYunWmlsb;
    private float mOtherPay;
    private PaySet mPayset;

    private List<DMFKFS>mDMFKFSList=new ArrayList<>();
    private OtherPayDetailAdapter mOtherPayDetailAdapter;
    private float mCashMoney;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_out);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        mConfirmDialog = ConfirmDialog.instance();

        CloseActivity.addAcitity(this);
        SharedPreferences user = getSharedPreferences("user", Context.MODE_PRIVATE);
        mPad = user.getString("pad", "");
        mOrderstytle = user.getString("orderstytle", getResources().getString(R.string.order_stytle_zhongxican));
        String cashpay = user.getString("cashpay", getString(R.string.cash_unallowed));
        if (cashpay.equals(getString(R.string.cash_allow))) {
            mRlXianjin.setVisibility(View.VISIBLE);
        } else {
            mRlXianjin.setVisibility(View.GONE);
        }
        mWmdbh = getIntent().getStringExtra("WMDBH");
        mPrinter = Prints.getPrinter();
        mPrinter.bindPrintService(this, connService);

        CartList.newInstance(this).setOrderNo(new OrderNo(mWmdbh, true));

        //其它付款方式
        View lvBottom = View.inflate(this, R.layout.listview_bottom_item, null);
        mListView.addFooterView(lvBottom);
        mListView.addHeaderView(View.inflate(this, R.layout.listview_top_item,null),null,false);
        mOtherPayDetailAdapter = new OtherPayDetailAdapter(this, mDMFKFSList);
        mListView.setAdapter(mOtherPayDetailAdapter);
        mListView.setOnItemClickListener(this);
        lvBottom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(Moneys.wfjr>0){
                    Toast.makeText(CheckOutActivity.this,"金额不足，请使用现金或扫码支付",Toast.LENGTH_SHORT).show();
                }else{
                    mProgressBar.setVisibility(View.VISIBLE);
                    Post6.getInstance().Http_other(mWmlsbjb,mDMFKFSList);
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        mTvUser.setText(Users.YHMC);
        //中西餐
        if (mOrderstytle.equals(getResources().getString(R.string.order_stytle_zhongxican))) {
            mLlChange.setVisibility(View.VISIBLE);
            mLinearLayout.setVisibility(View.VISIBLE);
            //快餐
        } else {
            mLlChange.setVisibility(View.INVISIBLE);
            mLinearLayout.setVisibility(View.INVISIBLE);
        }
        Http_initData();
    }

    private void Http_initData() {
        mProgressBar.setVisibility(View.VISIBLE);
        list_wmlsb.clear();
        mTotalMoney = 0.00f;
        mActualMoney = 0.00f;
        String sqlWmlsbjb = "select convert(varchar(10),getdate(),120) as sj,WMDBH,ZH,JCRS,YS,isnull(BY1,'')BY1,isnull(ZKFS,'无')ZKFS,convert(varchar(19), JYSJ,120)JYSJ,isnull(jcfs,'')jcfs,DJLSH,YHBH,JSJ " +
                "from WMLSBJB where WMDBH='" + mWmdbh + "'|";
        DownHTTP.postVolley6(Net.url, sqlWmlsbjb, new VolleyResultListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mProgressBar.setVisibility(View.GONE);
                Toast.makeText(CheckOutActivity.this, "数据加载失败", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onResponse(String response) {
                if (response.toLowerCase().contains("error")) {
                    Toast.makeText(CheckOutActivity.this, response, Toast.LENGTH_SHORT).show();
                    return;
                }
                Gson gson1 = new Gson();
                Wmslbjb_jiezhang[] wmslbjb = gson1.fromJson(response, Wmslbjb_jiezhang[].class);
                mWmlsbjb = wmslbjb[0];
                mTvTable.setText(mWmlsbjb.getZH());
                mTvTime.setText(mWmlsbjb.getJYSJ());
                mTvPersons.setText(mWmlsbjb.getJCRS() + "人");
                mTvOpener.setText(mWmlsbjb.getYHBH());

                String sqlWmlsb = "SELECT convert(varchar(30),getdate(),121) ZSSJ2, isnull(BY3,0)BY3,* FROM WMLSB WHERE WMDBH = '" + mWmdbh + "'|";
                DownHTTP.postVolley6(Net.url, sqlWmlsb, new VolleyResultListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        mProgressBar.setVisibility(View.GONE);
                        Toast.makeText(CheckOutActivity.this, "数据加载失败", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(String response) {
                        if (response.toLowerCase().contains("error")) {
                            Toast.makeText(CheckOutActivity.this, response, Toast.LENGTH_SHORT).show();
                            return;
                        }
                        if (response.equals("]")) {
                            mTvZonger.setText("￥" + 0.00);
                            mTvZekou.setText("￥" + 0.00);
                            mTvYishou.setText("￥" + 0.00);
                            mTvDaishou.setText("￥" + 0.00);
                            mProgressBar.setVisibility(View.GONE);
                            return;
                        }
                        Gson gson = new Gson();
                        mWmlsbs = gson.fromJson(response, WMLSB[].class);
                        for (WMLSB W : mWmlsbs) {
                            mTotalMoney = mTotalMoney + W.getYSJG() * W.getSL();
                            mActualMoney = mActualMoney + W.getDJ() * W.getSL();
                            list_wmlsb.add(W);
                        }

                        setMoneys();

                        mPrinter.setPrintMsg(mWmlsbjb, mWmlsbs);

                        mProgressBar.setVisibility(View.GONE);
                    }
                });
            }
        });
    }

    private void setMoneys() {
        mYingshou = bigDecimal(bigDecimal(mActualMoney) - bigDecimal(mYishou));
        Float zekou = bigDecimal(bigDecimal(mTotalMoney) - bigDecimal2(mActualMoney));
        Moneys.xfzr = bigDecimal(mTotalMoney);
        Moneys.zkjr = zekou;
        Moneys.ysjr = bigDecimal2(mYingshou);
        Moneys.wfjr = bigDecimal2(mYingshou-Moneys.yfjr);

        mTvZonger.setText("￥" + Moneys.xfzr);
        mTvZekou.setText("￥" + zekou);
        mTvYishou.setText("￥" + bigDecimal(Moneys.yfjr));
        mTvDaishou.setText("￥" + bigDecimal(Moneys.wfjr));
    }

    @OnClick({R.id.tv_discount, R.id.btn_dayin, R.id.btn_dingdan, R.id.rl_xianjin,
            R.id.rl_zhifubao, R.id.rl_weixin, R.id.ll_cashier, R.id.rl_yun,
            R.id.ll_change, R.id.rl_other})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_discount://类别折扣
                List<LBZKSZJBXX> lbzkszjbxxList = DataSupport.findAll(LBZKSZJBXX.class);
                if (lbzkszjbxxList.size() <= 0) {
                    Toast.makeText(this, "请在门店管理设置类别折扣方案再重新下载数据！", Toast.LENGTH_SHORT).show();
                } else {
                    KindDiscountFragment fragment = KindDiscountFragment.newInstance(lbzkszjbxxList);
                    fragment.show(getSupportFragmentManager(), null);
                    fragment.setOnDiscountClick(this);
                }
                break;
            case R.id.ll_change:
                Intent intent = new Intent();
                intent.putExtra("wmdbh", mWmdbh);
                intent.putExtra("zh", mWmlsbjb.getZH());
                setResult(RESURTCODE, intent);
                finish();
                break;
            case R.id.btn_dayin:
                mPrinter.setWoyouService(woyouService);
                mPrinter.print_yudayin();
                break;
            case R.id.btn_dingdan:
                if (mWmlsbjb != null) {
                    CartList.newInstance(this).clear();
                    mIntent = new Intent(this, CartDetailActivity.class);
                    mIntent.putExtra(ExtraParm.EXTRA_WMDBH, mWmlsbjb.getWMDBH());
                    startActivity(mIntent);
                } else {
                    Toast.makeText(this, "数据未完全加载, 不能进入订单详情", Toast.LENGTH_SHORT).show();
                }

                break;
            case R.id.rl_zhifubao:
                if (canCheck()) return;
                mPayset = DataSupport.findFirst(PaySet.class);
                if (mPayset == null || TextUtils.isEmpty(mPayset.getPID())) {
                    Toast.makeText(this, "您还未设置支付宝支付，请申请开通后到前台收银机设置", Toast.LENGTH_SHORT).show();
                    return;
                }

                toScanPayActivity(getString(R.string.payStytle_zhifubao));
                break;
            case R.id.rl_weixin:
                if (canCheck()) return;
                mPayset = DataSupport.findFirst(PaySet.class);
                if (mPayset == null || TextUtils.isEmpty(mPayset.getBY3())) {
                    Toast.makeText(this, "您还未设置微信支付，请申请开通后到前台收银机设置", Toast.LENGTH_SHORT).show();
                    return;
                }

                toScanPayActivity(getString(R.string.payStytle_weixin));
                break;
            case R.id.rl_yun:
                if (canCheck()) return;
                List<WXFWQDZ> list = DataSupport.select("weid", "SIP").find(WXFWQDZ.class);
                if (list.size() == 0 || TextUtils.isEmpty(list.get(0).getSIP())) {
                    Toast.makeText(this, "您还未设置云会员支付，请开通云会员后在前台收银机设置", Toast.LENGTH_SHORT).show();
                    return;
                }

                mIntent = new Intent(this, YunLandActivity.class);
                mIntent.putExtra("WMLSBJB", mWmlsbjb);
                mIntent.putExtra("listWmlsb", list_wmlsb);
                startActivityForResult(mIntent, YUPAYREQUEST);
                //
                mDMFKFSList.clear();
                Moneys.yfjr=0;
                setMoneys();
                mListView.setVisibility(View.GONE);
                break;
            case R.id.rl_xianjin:
                if (canCheck()) return;
                inputMoney();
                break;
            case R.id.rl_other:
                if (canCheck()) return;
                OtherPayFragment otherPayFragment = OtherPayFragment.newInstance();
                otherPayFragment.show(getSupportFragmentManager(), null);
                otherPayFragment.setOnItemClickListener(this);
                break;
        }
    }

    private void toScanPayActivity(String from) {
        mIntent = new Intent(this, WebViewPayActivity.class);
        mIntent.putExtra("WMLSBJB", mWmlsbjb);
        mIntent.putExtra("from", from);
        String sql_otherpay="";
        for(DMFKFS dmfkfs:mDMFKFSList){
            sql_otherpay+="insert into XSFKFS(XSDH,BM,NR,FKJE,DYQZS) values ('" + mWmlsbjb.getWMDBH() + "','" + dmfkfs.getBm() + "','" + dmfkfs.getNr() + "'," + dmfkfs.getMoney() + ","+dmfkfs.getDyqzs()+")|";
        }
        mIntent.putExtra("otherpay",sql_otherpay);
        startActivity(mIntent);
    }

    private boolean canCheck() {
        List<YHJBQK> yhjbqk = DataSupport.select("ZPQX").where("YHBH=?", Users.YHBH).find(YHJBQK.class);
        String zpqx = yhjbqk.get(0).getZPQX();
        if (!"1".equals(zpqx)) {
            mConfirmDialog.show(this, "当前账号没有结账权限，是否切换有结账权限账号登录？");
            mConfirmDialog.setOnconfirmClick(this);
            return true;
        }
        for (int i = 0; i < Users.ygsbbcs.length; i++) {
            Ygsbbc ygsbbc = Users.ygsbbcs[i];
            if (!ygsbbc.getYhbh().equals(Users.YHBH)) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("提示");
                builder.setIcon(R.mipmap.warn);
                builder.setMessage(ygsbbc.getYhbh() + ygsbbc.getYhmc() + " 尚未下班，请先用此账户登录并做下清机下班");
                builder.setPositiveButton("知道了", null);
                builder.show();
                return true;
            }
        }
        return false;
    }

    /**
     * 输入金额
     */
    private void inputMoney() {
        final CheckOutDialog dialog = new CheckOutDialog(this, "现金支付", "", Moneys.wfjr);
        dialog.mConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String money = dialog.mEtInput.getText().toString().trim();
                mCashMoney = Float.parseFloat(money);
                if (Moneys.wfjr > mCashMoney) {
                    Toast.makeText(CheckOutActivity.this, "输入金额不足", Toast.LENGTH_SHORT).show();
                    return;
                }
                mProgressBar.setVisibility(View.VISIBLE);
                Post6.getInstance().Http_cashier(CheckOutActivity.this, mWmlsbjb, mPad, mCashMoney, mCashMoney -Moneys.wfjr,mDMFKFSList);
                dialog.cancel();
            }
        });
    }

    /**
     * 云会员支付全额支付
     */
    @Subscribe
    public void getYunPayLocal(final YunSqlFinish event) {
        mProgressBar.setVisibility(View.VISIBLE);
        Post6.getInstance().Http_yun(this, event.wmlsbjb, event.sql);
    }

    @Subscribe
    public void yunSubmit(YunSubmit event) {
        mListYunWmlsb = event.mListWmlsb;
        mYunPayStytle = event.listPay;
        mOtherPay = event.otherPay;
    }

    @Subscribe
    public void checkSuccess(CheckSuccess event) {
        if (event.payStytle.equals("fail")) {
            return;
        }
        mPrinter.setWoyouService(woyouService);
        if (event.payStytle.equals(getResources().getString(R.string.payStytle_cash))) {//现金支付
            mPrinter.print_jiezhang(this,mCashMoney, Moneys.wfjr, event.payStytle,mDMFKFSList);
        } else if (event.payStytle.equals(getString(R.string.payStytle_zhifubao)) || event.payStytle.equals(getString(R.string.payStytle_weixin))) {//支付宝，微信
            mPrinter.print_jiezhang(this, 0, Moneys.wfjr, event.payStytle,mDMFKFSList);
        } else if (event.payStytle.equals(getResources().getString(R.string.payStytle_yun))) {//云会员支付
            mPrinter.print_yun(mWmlsbjb, mListYunWmlsb, mYunPayStytle, "", 0);
        }else if(event.payStytle.equals(getResources().getString(R.string.payStytle_other))){//其它付款方式
            mPrinter.print_other(mDMFKFSList);
        } else if (event.payStytle.equals(getString(R.string.payStytle_cash_yun))) {//云会员、现金支付
            mPrinter.print_yun(mWmlsbjb, mListYunWmlsb, mYunPayStytle, event.payStytle, mOtherPay);
        } else if (event.payStytle.equals(getString(R.string.payStytle_zhifubao_yun)) || event.payStytle.equals(getString(R.string.payStytle_weixin_yun))) {//云会员、扫码
            mPrinter.print_yun(mWmlsbjb, mListYunWmlsb, mYunPayStytle, event.payStytle, mOtherPay);
        }
        //快餐模式，下厨打印
        if (mOrderstytle.equals(getString(R.string.order_stytle_kuaican))) {
            OrderNo orderNo = CartList.newInstance(this).getOrderNo();
            SqlNetHandler.getInstance().handleCommit1(mHandler, this, orderNo);
        }
        mProgressBar.setVisibility(View.GONE);

        Moneys.yfjr = 0;
        Moneys.wfjr = Moneys.ysjr;
        finish();
    }

    @Subscribe
    public void finishActivity(FinishEvent event) {
        finish();
    }

    private Float bigDecimal(Float f) {
        return BigDecimal.valueOf(f).setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
    }

    private Float bigDecimal2(Float f){
        float roundMoney = 0;
        if(Users.rounding.equals(getString(R.string.rounding_jiao))){
            roundMoney=BigDecimal.valueOf(f).setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
        }else if(Users.rounding.equals(getString(R.string.rounding_yuan))){
            roundMoney=BigDecimal.valueOf(f).setScale(0, BigDecimal.ROUND_HALF_UP).floatValue();
        }
        return roundMoney;
    }

    //接口回调，dialog确定键监听
    @Override
    public void confirmListener() {
        EventBus.getDefault().post(new FinishEvent());
        mConfirmDialog.cancel();
    }

    /**
     * 类别折扣方案
     */
    @Override
    public void onDiscountClick(List<LBZKSZMXXX> lbzkszmxxxList, String mc) {
        String updateWmlsb = "";
        for (int i = 0; i < lbzkszmxxxList.size(); i++) {
            String lbbm = lbzkszmxxxList.get(i).getLBBM();
            String zkbl = lbzkszmxxxList.get(i).getZKBL();
            for (int j = 0; j < list_wmlsb.size(); j++) {
                WMLSB wmlsb = list_wmlsb.get(j);
                JYXMSZ jyxmsz = DataSupport.where("xmbh=? and bcyzddz=?", wmlsb.getXMBH(), "1").findFirst(JYXMSZ.class);
                if (lbbm.equals(wmlsb.getBy2()) && jyxmsz == null) {
                    float dj = bigDecimal(wmlsb.getYSJG() * (Float.parseFloat(zkbl) / 100));
                    float xj = bigDecimal(wmlsb.getSL() * dj);
                    updateWmlsb += "update wmlsb set dj=" + dj + ",xj=" + xj + ",by13='" + mc + "' where xh='" + wmlsb.getXH() + "'|";
                }
            }
        }
        if (!TextUtils.isEmpty(updateWmlsb)) {
            mProgressBar.setVisibility(View.VISIBLE);
            String sql = updateWmlsb + "update wmlsbjb set ys=(select sum(xj) from wmlsb where wmdbh='" + mWmlsbjb.getWMDBH() + "'),hykdj='" + mc + "' where wmdbh='" + mWmlsbjb.getWMDBH() + "'|";
            DownHTTP.postVolley7(Net.url, sql, new VolleyResultListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(CheckOutActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                    mProgressBar.setVisibility(View.GONE);
                }

                @Override
                public void onResponse(String response) {
                    if (response.contains("richado")) {
                        Http_initData();
                    }
                }
            });
        } else {
            Toast.makeText(CheckOutActivity.this, "没有可折扣的单品", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbindService(connService);
        EventBus.getDefault().unregister(this);
        Moneys.yfjr=0;
    }

    //其它付款方式返回
    @Override
    public void onItemClick(DMFKFS dmfkfs) {
        mListView.setVisibility(View.VISIBLE);
        mDMFKFSList.add(dmfkfs);
        mOtherPayDetailAdapter.setList(mDMFKFSList);
        float otherMoney=0f;
        for(DMFKFS d:mDMFKFSList){
            otherMoney+=d.getMoney();
        }
        Moneys.yfjr=otherMoney;
        setMoneys();
    }
    //其它付款方式删除
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        mDMFKFSList.remove(i-1);
        mOtherPayDetailAdapter.setList(mDMFKFSList);
        float otherMoney=0f;
        for(DMFKFS d:mDMFKFSList){
            otherMoney+=d.getMoney();
        }
        Moneys.yfjr=otherMoney;
        setMoneys();
        if(mDMFKFSList.size()<=0){
            mListView.setVisibility(View.GONE);
        }
    }
}
